// 戴朋
#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int suma = 0, sumb = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    suma += a[i];
  }
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    sumb += b[i];
  }

  // 或者 a降序，b升序。也可以

  // 双指针用法

  sort(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<int>());
  int j = 0;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] + b[j] >= m && j < n) {
      cnt++;
       j++;
    }
  }
  int ans = suma + sumb - m * cnt;
  cout << ans << endl;
  return;
}
signed main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}